<template>
  <div class="component-list" @dragstart="handleDragStart">
    <div
      v-for="(item,index) in componentList"
      :key="item"
      class="list"
      draggable="true"
      :data-index="index"
    >
      <span class="iconfont" :class="`icon-${item.icon}`"></span>
    </div>
  </div>
</template>

<script lang="ts" setup>
import componentList from "@/components/custom/component-list.ts";

const handleDragStart = (e: DragEvent) => {
  (e.dataTransfer as DataTransfer).setData("index",<string>((e.target as any).dataset.index));
};
</script>

<style lang="scss" scoped>
.component-list {
  height: 65%;
  padding: 10px;
  display: grid;
  grid-gap: 10px 19px;
  grid-template-columns: repeat(auto-fill, 80px);
  grid-template-rows: repeat(auto-fill, 40px);

  .list {
    width: 80px;
    height: 40px;
    border: 1px solid #ddd;
    cursor: grab;
    text-align: center;
    color: #333;
    padding: 2px 5px;
    display: flex;
    align-items: center;
    justify-content: center;

    &:active {
      cursor: grabbing;
    }

    .iconfont {
      margin-right: 4px;
      font-size: 20px;
    }

    .icon-text,
    .icon-table {
      font-size: 18px;
    }

    .icon-picture {
      font-size: 16px;
    }
  }
}
</style>
